home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
-
- FICHERO: PSCRIPT.C
-
- AUTOR: ANTONIO LADESA JURADO
-
- FECHA: 24/6/94
-
- DESCRIPCION:
-
- Fichero que contiene las estructuras, constantes, variables y funciones
- internas y externas para la impresión de las imágenes en lenguaje PostScript.
-
- ==============================================================================*/
-
-
- /*---- MODULOS USADOS --------------------------------------------------------*/
-
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include <string.h>
-
- #include "global.h"
- #include "memoria.h"
- #include "video.h"
- #include "pscript.h"
- #include "color.h"
- #include "error.h"
-
- /*---- DEFINICION DE LAS FUNCIONES INTERNAS ----------------------------------*/
-
-
- void POSTSCRIPTescribirCodigo(IMAGEN *c,FILE *f);
-
-
- /*---- CODIFICACION DE LAS FUNCIONES OFRECIDAS -------------------------------*/
-
-
- /*---- FUNCION: extern int POSTSCRIPTimprimir(IMAGEN *c,char *nombre) ----------
-
- Descripción:
-
- Esta función envía una imagen en lenguaje PostScript a la impresora o
- a un fichero.
-
- Parámetros:
-
- IMAGEN *c : puntero a estructura que alberga la imagen
- char *nombre : nombre del fichero de salida (o cte = "IMPRESORA")
-
- Retorno:
-
- - 1 si hubo éxito.
- - 0 si hubo error.
-
- ---- CODIGO: -----------------------------------------------------------------*/
-
- extern int POSTSCRIPTimprimir(IMAGEN *c,char *nombre)
- {
- /* puntero al fichero */
- FILE *f;
- /* puntero a la imagen duplicada */
- IMAGEN *r = NULL;
-
- /* si no hay imagen, error */
- if(c==NULL)
- {
- ERRORponer(ERRnoImagen);
- return(0);
- }
- /* duplicar la imagen para transformarla */
- if((r = IMAGENduplicar(c))==NULL)
- {
- ERRORponer(ERRnoMemoria);
- return(0);
- }
-
- /* adaptar el modo de vídeo */
- if(r->modo == VIDEOega)
- r = VIDEOvision(r);
-
- /* si el destino es el disco */
- if(strcmp(nombre,"IMPRESORA"))
- {
- /* abrir el fichero */
- if((f = fopen(nombre, "wb")) == NULL)
- {
- ERRORponer(ERRapertura);
- r = MEMliberar(r);
- return(0);
- }
- /* escribir la imagen POSTSCRIPT */
- POSTSCRIPTescribirCodigo(r,f);
- /* cerrar el fichero */
- fclose(f);
- }
- else
- /* si es la impresora, imprimir */
- POSTSCRIPTescribirCodigo(r,stdprn);
- /* liberar imagen duplicada */
- r=MEMliberar(r);
- return(1);
- }
-
- /*---- FIN FUNCION -----------------------------------------------------------*/
-
-
- /*---- CODIFICACION DE LAS FUNCIONES INTERNAS --------------------------------*/
-
-
- /*---- FUNCION: void POSTSCRIPTescribirCodigo(IMAGEN *c,FILE *f) ---------------
-
- Descripción:
-
- Esta función escribe en el fichero o impresora las ordenes PostScript
- para imprimir la imagen
-
- Parámetros:
-
- IMAGEN *c : puntero a la estructura que alberga la imagen
- FILE *f : puntero al fichero ( o a stdprn)
-
- ---- CODIGO: -----------------------------------------------------------------*/
-
- void POSTSCRIPTescribirCodigo(IMAGEN *c,FILE *f)
- {
- /* buffer */
- char p[ANCHO_MAXIMO];
- /* contadores */
- int i,j;
- /* valores a modificar según el modo de vídeo */
- int ancho,alto,bits,ppp;
-
- /* adecuar dimensiones y número de bits por pixel según el modo de vídeo */
- switch(c->modo)
- {
- case VIDEOmono:
- ppp = 640;
- ancho = (640/ppp)*(c->ancho/8);
- alto = (640/ppp)*(c->alto/8);
- bits = 1;
- break;
- case VIDEOvga:
- c = PonerGris(c);
- ppp = 96;
- ancho = (int)((double)c->ancho*0.75);
- alto = (int)((double)c->alto*0.75);
- bits = 8;
- break;
- };
-
- /* código postscript */
- fprintf(f,"%%!PS_Adobe-2.0\r\n");
- fprintf(f,"%%%%BoundingBox: 0 0 %u %u\r\n",ancho,alto);
- fprintf(f,"%%%%Creator: CIMB. Antonio Ladesa.\r\n");
- fprintf(f,"%%%%Title: %s\r\n",c->nombre);
- fprintf(f,"/width %u deftity: %u %u %u 1 %u %u 1\r\n",
- c->ancho,c->ancho,c->alto,bits,ppp,c->bytes);
- fprintf(f,"/height %u def\r\n",c->alto);
- fprintf(f,"/glevel %u def\r\n",bits);
- fprintf(f,"/dpi %u def\r\n",ppp);
- fprintf(f,"/istr %u string def\r\n",c->ancho);
- fprintf(f,"/nheight height neg def\r\n");
- fprintf(f,"/imageturkeypi div mul } def\r\n");
- fprintf(f,"{ width height glevel [width 0 0 nheight 0 height]\r\n");
- fprintf(f," { currentfile istr readhexstring pop } image\r\n");
- fprintf(f,"} def\r\n");
- fprintf(f,"gsave\r\n");
- fprintf(f,"0 0 translate\r\n");
- fprintf(f,"width dot height dot scale\r\n");
- fprintf(f,"imageturkey\r\n");
-
- /* datos de la imagen */
- for(i=0;i<c->alto;++i)
- {
- MEMleer(p,i,c);
- for(j=0;j<c->ancho;++j)
- fprintf(f,"%02.2X",p[j]);
- fprintf(f,"\r\n");
- }
- fprintf(f,"grestore\r\n");
- fprintf(f,"showpage\r\n");
- }
-
- /*---- FIN FUNCION -----------------------------------------------------------*/